<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas{
            border:1px solid #ccc;
        }
    </style>
</head>
<body>
    <script>
        (()=>{
            const canvas = document.createElement('canvas');
            document.body.append(canvas);
            canvas.width=400;
            canvas.height=400;

            const ctx = canvas.getContext('2d');
            ctx.fillRect(100,100,200,100);
        })();

        (()=>{
            const canvas = document.createElement('canvas');
            document.body.append(canvas);
            canvas.width=400;
            canvas.height=400;

            const ctx = canvas.getContext('2d');
            ctx.strokeRect(100,100,200,100);
        })();

        (()=>{
            const canvas = document.createElement('canvas');
            document.body.append(canvas);
            canvas.width=400;
            canvas.height=400;
            
            const ctx = canvas.getContext('2d');
            ctx.rect(100,100,200,100);
            ctx.fillStyle = 'rgba(255,0,0,0.8)'
            ctx.strokeStyle = '#00f';
            ctx.lineWidth = 10 ;
            ctx.stroke();
            ctx.fill();
            //代码至此，已经绘画完毕了
            //ctx.fillStyle = 'red' ; //无效果
        })();

    </script>
</body>
</html>